{include file="header.html"}
<body>

<div class="navBar navBar-transparent">
	<a class="left" href="javascript:history.back()"><i class="return"></i></a>
	<div class="titleView">注册</div>
	<a class="right" href="?tpl=login&url={urlencode($url)}">登录</a>
</div>

<div class="login-index width-wrap">
	<form action="api.php?app=passport&act=register" method="post">
	<input type="hidden" name="gourl" value="{if $url==''}wap.php?app=member&act=index{else}{$url}{/if}" />
	<ul class="inputView">
		<li class="ge-bottom"><div><i></i><input type="tel" name="mobile" id="mobile" /></div></li>
		<li class="ge-bottom"><div class="code"><a href="javascript:void(0)"><span>发送短信</span></a><i></i><input type="text" name="code" id="code" /></div></li>
		<li class="ge-bottom"><div class="password"><em></em><i></i><input type="password" name="password" id="password" /></div></li>
		<div class="buttonView">
			<a href="javascript:void(0)" class="btn">注册</a>
		</div>
		<a href="?app=article&act=detail&id=3">注册即视为同意《商富商城服务协议》</a>
	</ul>
	</form>
</div>

{include file="footer.html"}
<script>
var _mobileText = '', _codeText = '', _getCode = false, _count = 0, _timer = null;
function myFn(){
	if(!$('#mobile').val().length){
		$.overloadError('请输入手机号码');
		return;
	}
	if(!$('#code').val().length){
		$.overloadError('请输入验证码');
		return;
	}
	if(!$('#password').val().length){
		$.overloadError('请输入密码');
		return;
	}
	if($('#code').val()!=_codeText){
		$.overloadError('验证码不正确');
		return;
	}
	$('form').submit();
}
$(function(){
	$('html, body').addClass('height-wrap');
	$('#mobile').placeholder('请输入手机号码(注册后不可更改)');
	$('#code').placeholder('请输入验证码');
	$('#password').placeholder('请输入密码').onkey({
		callback : function(code){
			if(code==13)myFn();
		}
	});
	$('.password em').click(function(){
		var input = $('#password');
		if(!!input.data('show')){
			input.removeData('show');
			input.prop('type', 'password');
			$(this).removeClass('x');
		}else{
			input.data('show', true);
			input.prop('type', 'text');
			$(this).addClass('x');
		}
	});
	$('.code a').click(function(){
		if(_getCode)return false;
		if(!$('#mobile').val().length){
			$.overloadError('请输入手机号码');
			return false;
		}
		var _this = $(this).html('<div class="preloader"></div>');
		_getCode = true;
		_mobileText = _codeText = '';
		$.postJSON('api.php?app=passport&act=check_mobile', { mobile:$('#mobile').val() }, function(json){
			if(json.error!=0){
				$.overloadError(json.msg);
				return;
			}
			_mobileText = json.data.mobile;
			_codeText = json.data.code;
			_count = 60;
			_timer = setInterval(function(){
				_count--;
				if (_count<=0) {
					clearInterval(_timer);_getCode = false;
					_this.removeClass('disabled').html('<span>再次发送</span>');
				} else {
					_this.addClass('disabled').html('<span>'+_count+'s后重发</span>');
				}
			}, 1000);
		});
	});
	$('.btn').click(function(){
		myFn();
		return false;
	});
});
</script>
